<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!-- page start from 0, the jsp display from 1 -->
<c:if test="${page.totalCount > 0}">
<div class="pager">
	<c:set var="pager_url_prefix">
		<c:choose>
			<c:when test="${fn:containsIgnoreCase(page.url, '?')}">${page.url}&</c:when>
			<c:otherwise>${page.url}?</c:otherwise>
		</c:choose>
	</c:set>
	<table cellpadding="0" cellspacing="0">
		<tr>
			<td>
			<a href="<c:url value='${pager_url_prefix}pi=1_${page.pageSize}'/>"><fmt:message key="common.pager.html.first"/></a>
			</td>
			<td>
			<c:if test="${page.totalPage - page.pageIndex > 0}">
				<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex + 1}_${page.pageSize}'/>"><fmt:message key="common.pager.html.next"/></a>
			</c:if>
			</td>
			<td>
				<c:if test="${page.totalPage > 0}">
					<!-- the displayed page before current page -->
					<c:if test="${page.pageIndex - 2 >= 1}"><!-- current page > 3 -->
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex - 2}_${page.pageSize}'/>">${page.pageIndex - 2}</a>
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex - 1}_${page.pageSize}'/>">${page.pageIndex - 1}</a>
					</c:if>
					<c:if test="${page.pageIndex - 2 == 0}"> <!-- current page == 2 -->
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex - 1}_${page.pageSize}'/>">${page.pageIndex - 1}</a>
					</c:if>
					
					<!-- current page -->
					<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex}_${page.pageSize}'/>"><strong><font color="#ff0000">${page.pageIndex}</font></strong></a>
					
					<!-- thie displayed page after current page -->
					<c:if test="${page.totalPage - page.pageIndex - 2 >= 0 }">
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex + 1}_${page.pageSize}'/>">${page.pageIndex + 1}</a>
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex + 2}_${page.pageSize}'/>">${page.pageIndex + 2}</a>
					</c:if>
					<c:if test="${page.totalPage - page.pageIndex - 2  == -1}"> <!-- current page == 2 -->
						<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex + 1}_${page.pageSize}'/>">${page.pageIndex + 1}</a>
					</c:if>
				</c:if>
			</td>
			<td>
				<c:if test="${page.pageIndex - 1 > 0}"> <!-- make sure current page > 1 show 'prev' -->
					<a href="<c:url value='${pager_url_prefix}pi=${page.pageIndex - 1}_${page.pageSize}'/>"><fmt:message key="common.pager.html.pre"/></a>
				</c:if>
			</td>
			<td>
				<a href="<c:url value='${pager_url_prefix}pi=${page.totalPage}_${page.pageSize}'/>"><fmt:message key="common.pager.html.last"/></a>
			</td>
			<td>
				&nbsp;&nbsp;<fmt:message key="common.pager.html.total"/>${page.totalCount}<fmt:message key="common.pager.html.total.record"/>
				&nbsp;&nbsp;<fmt:message key="common.pager.html.total"/>${page.totalPage }<fmt:message key="common.pager.html.total.page"/>
			</td>
			<td>
				&nbsp;&nbsp;
				<a href="javascript:goPagination(this)">
				<fmt:message key="common.pager.html.goto"/>
				</a>
				<input type="text" name="pagination_pageIndex" id="pagination_pageIndex" size="2"/>页
			</td>
		</tr>
	</table>
</div>
</c:if>
<script>
function goPagination(input){
	var pageIndex = document.getElementById('pagination_pageIndex').value;
	var pagerurl = '<c:out value="${page.url}" escapeXml="false"/>';
	if(pagerurl.indexOf('?') != -1){
		pagerurl = pagerurl + '&';
	}else{
		pagerurl = pagerurl + '?';
	}
	var url = ctx + pagerurl + "pi=" + pageIndex + '_<c:out value="${page.pageSize}"/>';
	location.href = url;
}
</script>